package cn.microven.mindmap.components.line;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.shape.*;

/**
 * 节点之间的连线
 * 通过 Path 实现曲线，同时接口设计仿照 JavaFX 中 Line 的接口设计
 *
 * @see cn.microven.mindmap.components.node.AbstractMapNode
 * @author 吴博维
 * @version 1.0
 */
public class MapLine extends Path {

    protected MoveTo start;

    protected QuadCurveTo quad;

    protected SimpleDoubleProperty startX;

    protected SimpleDoubleProperty startY;

    protected SimpleDoubleProperty endX;

    protected SimpleDoubleProperty endY;

    public MapLine() {
        start = new MoveTo();
        quad = new QuadCurveTo();
        startX = new SimpleDoubleProperty();
        startY = new SimpleDoubleProperty();
        endX = new SimpleDoubleProperty();
        endY = new SimpleDoubleProperty();
        start.xProperty().bindBidirectional(startX);
        start.yProperty().bindBidirectional(startY);
        quad.xProperty().bindBidirectional(endX);
        quad.yProperty().bindBidirectional(endY);
        quad.controlYProperty().bind(endY);
        quad.controlXProperty().bind(startX.add(endX).divide(10));
        this.setSmooth(true);
        this.getElements().add(start);
        this.getElements().add(quad);
        this.setStrokeLineJoin(StrokeLineJoin.BEVEL);
    }

    public double getStartX() {
        return startX.get();
    }

    public double getStartY() {
        return startY.get();
    }

    public double getEndX() {
        return endX.get();
    }

    public double getEndY() {
        return endY.get();
    }

    public SimpleDoubleProperty endXProperty() {
        return endX;
    }

    public SimpleDoubleProperty endYProperty() {
        return endY;
    }

    public SimpleDoubleProperty startXProperty() {
        return startX;
    }

    public SimpleDoubleProperty startYProperty() {
        return startY;
    }

    public void setStartX(double x) {
        start.setX(x);
    }

    public void setStartY(double y) {
        start.setY(y);
    }

    public void setEndX(double x) {
        quad.setX(x);
    }

    public void setEndY(double y) {
        quad.setX(y);
    }

    public QuadCurveTo getQuad() {
        return quad;
    }
}
